/**
 *  DBEXEL is a Database Backed & Web-Based Worksheet and chart management program. 
 *  It has been influenced by Excel.
 *  For questions or suggestions please contact the developper at ( Development@Gandomi.com )
 *  Copyright (C) 2011 Baubak Gandomi   
 *
 *	This file is part of the application DBEXEL
 *
 *   DBEXEL is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   DBEXEL is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package dbexel.model.mapping;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;

@Entity
@Table(name = "ATTRIBUTE")
public class WorkSheet_Attribute {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ATTR_ID")
	private Long attrId;

	@Column(name = "ATTR_NAME")
	private String attrName;

	@OneToMany(mappedBy = "attribute")
	@ForeignKey(name="FK_ATTRIBUTE_ATTRIBUTEVALUE")
	private List<AttributeValue> attrValues;

	@ManyToOne
	private WorkSheet workSheet;

	
	public void addAttrValue(AttributeValue in_attrVal) {
		this.getAttrValues().add(in_attrVal);
		
		in_attrVal.setAttribute(this);
	}

	public WorkSheet_Attribute() {
		attrName = "";
		setAttrValues(new ArrayList<AttributeValue>());
	}

	public WorkSheet_Attribute(String in_attrName) {
		attrName = in_attrName;
		setAttrValues(new ArrayList<AttributeValue>());
	}

	public Long getAttrId() {
		return attrId;
	}

	public void setAttrId(Long in_attrId) {
		attrId = in_attrId;
	}

	public String getAttrName() {
		return attrName;
	}

	public void setAttrName(String in_attrName) {
		attrName = in_attrName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((attrId == null) ? 0 : attrId.hashCode());
		result = prime * result
				+ ((attrName == null) ? 0 : attrName.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		WorkSheet_Attribute other = (WorkSheet_Attribute) obj;
		if (attrId == null) {
			if (other.attrId != null)
				return false;
		} else if (!attrId.equals(other.attrId))
			return false;
		if (attrName == null) {
			if (other.attrName != null)
				return false;
		} else if (!attrName.equals(other.attrName))
			return false;
		return true;
	}

	/**
	 * @return the workSheet
	 */
	public WorkSheet getWorkSheet() {
		return workSheet;
	}

	/**
	 * @param workSheet
	 *            the workSheet to set
	 */
	public void setWorkSheet(WorkSheet workSheet) {
		this.workSheet = workSheet;
	}

	/**
	 * @return the attrValues
	 */
	public List<AttributeValue> getAttrValues() {
		return attrValues;
	}

	/**
	 * @param attrValues the attrValues to set
	 */
	public void setAttrValues(List<AttributeValue> attrValues) {
		this.attrValues = attrValues;
	}
}
